package com.es.hr.manage;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

import com.es.hr.emp.EmpInfoBean;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class UpdateEmpInfoDoAction extends ActionSupport implements ServletRequestAware{

	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	 
	public String execute()throws Exception
	{
	   EmpInfoBean bean = getEmpInfoBean(request);
	   ManageBiz biz = new ManageBiz();
	   boolean bool = biz.updateEmpInfoDo(bean);
	   if(bool)
		   request.setAttribute("message", "更新人员信息操作成功！");
	   else
		   request.setAttribute("message", "更新人员信息操作产生错误！");
	   return "success";
	}

	public void setServletRequest(HttpServletRequest request) {
	     this.request = request;
	}
	
	public EmpInfoBean getEmpInfoBean(HttpServletRequest request) throws SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException{
		Field[] fds = Class.forName("com.es.hr.emp.EmpInfoBean").getDeclaredFields();   
		  EmpInfoBean bean = new EmpInfoBean();
		 
		  for(int i=0;i<fds.length;i++)   
		  {   
			  String d= fds[i].getName();
			  if(d.equals("emp_id"))
				  bean.setEmp_id(Long.valueOf(request.getParameter(d)));
			  else
				  fds[i].set(bean, request.getParameter(d));
		  }
		  return bean;
	}
}
